<?php
include 'api.php';
include 'connect_pdo.php';

try{
	//$data = $api->getItemsApi()->getItem(71077);//send request
	
	$data = $api->getCharacterApi()->getCharacter('magtheridon', 'mightybob', array('achievements'));
	print_r($data);
}
catch(exception $e)
{echo $e;}

/*
$da = $data['achievements']['criteria'];

foreach ($da as $var => $info)//for each achievement criteria
{
	echo $var;
	echo "id: ".$info."<br/>";
	echo $data['achievements']['criteriaQuantity'][$var]."<br/>";
}
*/

$a = $data;
//print_r($a['achievements']);
	$rx = 0;
	$rc = 0;
	
//print_r($a['achievements']);	
	
	foreach($a as $order => $cat)//for each achievement
	{
		//print_r($cat);
		//if (isset($cat['achievements']))
		if (isset($cat))
		{
			foreach($cat['achievements'] as $d => $achi)
			{
				$tooltip = '<div style="width:100%;style="color:#FFB100""><span style="float:right;">' . $achi['points'] . ' Points</span>' . $achi['title'] . '</div><br>' . $achi['description'] . '';
				$crit='';
				$crit .= '<br><div class="meta-achievements"><ul>';
				foreach ($achi['criteria'] as $r => $d)
				{
					$crit .= '<li><div id="crt'.$d['id'].'">'.$d['description'].'</div></li>';
					//echo $querystr.'<br>';
					$rc++;
				}
				$crit .= '</ul></div>';
				$tooltip .= $crit;

				//echo$querystr.'<br>';
				$rx++;
				//*/
			}
		}//end ach
		if (isset($cat['categories']))
		{
			foreach($cat['categories'] as $corder => $sub)
			{
				//echo '--'.$sub['name'].' - '.$sub['id'].'<br>';
				foreach($sub['achievements'] as $d => $achi)
				{	
					$tooltip = '<div style="width:100%;style="color:#FFB100""><span style="float:right;">' . $achi['points'] . ' Points</span>' . $achi['title'] . '</div><br>' . $achi['description'] . '';
					$crit='';
					$crit .= '<br><div class="meta-achievements"><ul>';
					foreach ($achi['criteria'] as $r => $d)
					{
						$crit .= '<li>'.$d['description'].'</li>';
		
						//echo $querystr.'<br>';
						$rc++;
					}
					$crit .= '</ul></div>';
						
					$tooltip .= $crit;
							$rx++;
					//*/
				}
			}
		}//end cats
	}
	
	
	

?>